<?php

namespace Home\Controller;

use Home\Biz\AddressBiz;
use Home\Biz\AdminBiz;
use Home\Biz\CommonBiz;
use Home\Biz\DealerBiz;
use Home\Biz\OrderBiz;
use Home\Biz\OrderInfoBiz;
use Home\Biz\SaleBiz;
use Home\Biz\UserBiz;
use Think\Controller;

/**
 * 页面ajax请求服务处理Controller
 *
 * @author Simon
 *        
 */
class AjaxServiceController extends Controller {
	
	/**
	 * Ajax服务中转类
	 */
	public function center($moudle, $util) {
		CommonBiz::saveOperation ( cookie ( 'login_user_id' ), 1, C ( 'AdminConfig.system_domain' ), $moudle, $util, CommonBiz::getParamsStr () );
		
		switch (strtolower ( $moudle )) {
			case 'user' :
				$this->userService ( $util );
				return;
			case 'sale' :
				$this->saleService ( $util );
				return;
			case 'address' :
				$this->addressService ( $util );
				return;
			case 'admin' :
				$this->adminService ( $util );
				return;
			case 'common' :
				$this->commonService ( $util );
				return;
			case 'order' :
				$this->orderService ( $util );
				return;
			case 'dealer' :
				$this->dealerService ( $util );
				return;
			default :
				$this->responseFail ( 5, '无法找到服务模块' );
		}
	}
	public function addressService($util) {
		switch (strtolower ( $util )) {
			case 'saveorupdate' :
				$address_id = I ( 'address_id' );
				$address = array (
						'user_id' => I ( 'user_id' ),
						'consignee_name' => I ( 'consignee_name' ),
						'consignee_cellphone' => I ( 'consignee_cellphone' ),
						'consignee_tel' => I ( 'consignee_tel' ),
						'consignee_province_id' => I ( 'consignee_province_id' ),
						'consignee_province' => I ( 'consignee_province' ),
						'consignee_city_id' => I ( 'consignee_city_id' ),
						'consignee_city' => I ( 'consignee_city' ),
						'consignee_district_id' => I ( 'consignee_district_id' ),
						'consignee_district' => I ( 'consignee_district' ),
						'consignee_address' => I ( 'consignee_address' ),
						'consignee_zip' => I ( 'consignee_zip' ) 
				);
				
				if (empty ( $address_id )) { // 新增
					$address ['address_id'] = AddressBiz::generateId ();
					$address ['create_user'] = "whaleyinfo.info AddressBiz.addAddress";
					$address ['create_date'] = date ( "y-m-d H:i:s", time () );
					
					$msg = AddressBiz::addAddress ( $address );
					if (! empty ( $msg )) {
						$this->responseFail ( 500, $msg );
					} else {
						$this->responseSuccess ();
					}
					// $this->responseSuccess();
					return;
				} else {
					$address ['address_id'] = I ( 'address_id' );
					$address ['update_user'] = "whaleyinfo.info AddressBiz.updateAddress";
					$address ['update_date'] = date ( "y-m-d H:i:s", time () );
					
					$msg = AddressBiz::updateAddress ( $address );
					if (! empty ( $msg )) {
						$this->responseFail ( 500, $msg );
					} else {
						$this->responseSuccess ();
					}
					
					return;
				}
			
			case 'queryaddress' :
				$result = AddressBiz::queryAddress ( I ( 'user_id' ), I ( 'consignee_name' ), I ( 'pageSize' ), I ( 'index' ) );
				$this->responseSuccess ( $result );
				return;
			case 'deletebyid' :
				$result = AddressBiz::deleteById ( I ( 'address_id' ) );
				if (! empty ( $result )) {
					$this->responseFail ( 500, $result );
				} else {
					$this->responseSuccess ();
				}
				return;
		}
	}
	public function saleService($util) {
		switch (strtolower ( $util )) {
			
			case 'addsale' :
				$sale_id = UserBiz::generateId ();
				
				$sale_add_en = array (
						'sale_id' => $sale_id,
						'sale_name' => I ( 'sale_name' ),
						'sale_real_name' => I ( 'sale_real_name' ),
						'sale_channel' => I ( 'sale_channel' ),
						'area_name' => I ( 'area_name' ),
						'password' => I ( 'password' ),
						'sale_mobile' => I ( 'sale_mobile' ),
						'province_id' => I ( 'province_id' ),
						'province_name' => I ( 'province_name' ),
						'city_id' => I ( 'city_id' ),
						'city_name' => I ( 'city_name' ),
						'district_id' => I ( 'district_id' ),
						'district_name' => I ( 'district_name' ),
						'department' => I ( 'department' ),
						'occupation' => I ( 'occupation' ),
						'sale_level' =>I('sale_level'),
						'sale_level_name'=>I('sale_level_name'),
						'resp_area' => I ( 'resp_area' ),
						'email_address' => I ( 'email_address' ),
						'remark' => I ( 'remark' ),
						'sale_address' => I ( 'sale_address' ),
						'create_sale' => "whaleyinfo.order SaleBiz.addSale",
						'create_date' => date ( "y-m-d H:i:s", time () ) 
				);
				$error_msg = SaleBiz::addsale ( $sale_add_en );
				if (empty ( $error_msg )) {
					$this->responseSuccess ();
				} else {
					$this->responseFail ( 5, $error_msg );
				}
				break;
			
			case 'updatesale' :
				$sale_id = I ( 'sale_id' );
				$sale_add_en = array (
						'sale_id' => $sale_id,
						'sale_name' => I ( 'sale_name' ),
						'sale_real_name' => I ( 'sale_real_name' ),
						'area_name' => I ( 'area_name' ),
						'province_id' => I ( 'province_id' ),
						'province_name' => I ( 'province_name' ),
						'city_id' => I ( 'city_id' ),
						'city_name' => I ( 'city_name' ),
						'district_id' => I ( 'district_id' ),
						'district_name' => I ( 'district_name' ),
						'password' => I ( 'password' ),
						'sale_mobile' => I ( 'sale_mobile' ),
						'department' => I ( 'department' ),
						'occupation' => I ( 'occupation' ),
						'sale_level' =>I('sale_level'),
						'sale_level_name'=>I('sale_level_name'),
						'resp_area' => I ( 'resp_area' ),
						'email_address' => I ( 'email_address' ),
						'remark' => I ( 'remark' ),
						'sale_address' => I ( 'sale_address' ),
						'create_sale' => "whaleyinfo.order SaleBiz.addSale",
						'create_date' => date ( "y-m-d H:i:s", time () ) 
				);
				$error_msg = SaleBiz::updatesale ( $sale_add_en );
				if (empty ( $error_msg )) {
					$this->responseSuccess ();
				} else {
					$this->responseFail ( 5, $error_msg );
				}
				break;
			
			case 'querysalebypara' :
				$sale_name = I ( 'sale_name' );
				$sale_mobile = I ( 'sale_mobile' );
				$sale_channel = I ( 'sale_channel' );
				$area_name = I ( 'area_name' );
				$department = I ( 'department' );
				$occupation = I ( 'occupation' );
				$sale_id = I('sale_id');
			
				$pageSize = I ( 'pageSize' );
				$index = I ( 'index' );
				$lst_res = SaleBiz::querySaleByPara ( $sale_id, $sale_name, $sale_mobile, $area_name, $department, $occupation, $sale_channel, $pageSize, $index );
				$this->responseSuccess ( $lst_res );
				break;
			case 'querysalebyparaforsearch' :
				$sale_name = I ( 'sale_name' );
				$sale_mobile = I ( 'sale_mobile' );
				$sale_channel = I ( 'sale_channel' );
				$area_name = I ( 'area_name' );
				$department = I ( 'department' );
				$occupation = I ( 'occupation' );
				$sale_id=I('sale_id');
				$type=I('type');
				$pageSize = I ( 'pageSize' );
				$index = I ( 'index' );
				$lst_res = SaleBiz::querySaleByParaForSearch ( $sale_id, $sale_name, $sale_mobile, $area_name, $department, $occupation, $sale_channel,$type, $pageSize, $index );
				$this->responseSuccess ( $lst_res );
				break;
			case 'querydealerbysaleid' :
				$sale_id = I ( 'sale_id' );
				$pageSize = I ( 'pageSize' );
				$index = I ( 'index' );
				$lst_res = SaleBiz::queryDealerBySaleId ( $sale_id, $pageSize, $index );
				$this->responseSuccess ( $lst_res );
				break;
			
			case 'querydealerbysaleandpara' :
				$sale_id = cookie ( 'login_user_id' );
				$sale_en = M ( 'sale_user' )->where ( "sale_name='%s'", $sale_id )->find ();
				// $sale_id = 'USR11147258';
				$dealer_name = I ( 'dealer_name' );
				$dealer_type = I ( 'dealer_type' );
				$business_leader = I ( 'business_leader' );
				$area_name = I ( 'area_name' );
				$sign_status = I ( 'sign_status' );
				$status = I ( 'status' );
				$k3_code = I ( 'k3_code' );
				$dealer_channel = I ( 'dealer_channel' );
				$pageSize = I ( 'pageSize' );
				$index = I ( 'index' );
				$lst_res = SaleBiz::queryDealerBySaleAndPara ( $sale_en ['sale_id'], $dealer_name, $dealer_type, $business_leader, $area_name, $sign_status, $status, $k3_code, $dealer_channel, $pageSize, $index );
				$this->responseSuccess ( $lst_res );
				break;
			case 'querydealersalerelationship' :
				$sale_id = I ( 'sale_id' );
				$dealer_id = I ( 'dealer_id' );
				
				$lst_res = SaleBiz::queryDealerSaleRelationship ( $sale_id, $dealer_id );
				$this->responseSuccess ( $lst_res );
				break;
			
			case 'adddealersalerelationship' :
				$sale_id = I ( 'sale_id' );
				$dealer_id = I ( 'dealer_id' );
				
				$lst_res = SaleBiz::addDealerSaleRelationship ( $sale_id, $dealer_id );
				$this->responseSuccess ( $lst_res );
				break;
			
			case 'deldealersalerelationship' :
				$sale_id = I ( 'sale_id' );
				$dealer_id = I ( 'dealer_id' );
				$lst_res = SaleBiz::delDealerSaleRelationship ( $sale_id, $dealer_id );
				$this->responseSuccess ( $lst_res );
				break;
			
			case 'querydealerwithoutrelationship' :
				
				$dealer_name = I ( 'dealer_name' );
				$dealer_type = I ( 'dealer_type' );
				$business_leader = I ( 'business_leader' );
				$area_name = I ( 'area_name' );
				$dealer_channel = I ( 'dealer_channel' );
				$sign_status = I ( 'sign_status' );
				$status = I ( 'status' );
				$pageSize = I ( 'pageSize' );
				$index = I ( 'index' );
				$lst_res = SaleBiz::queryDealerWithoutRelationship ( $dealer_name, $dealer_type, $business_leader, $area_name, $sign_status, $status, $dealer_channel, $pageSize, $index );
				$this->responseSuccess ( $lst_res );
			case 'querysalepreandsublevel':
				$sale_id = I ( 'sale_id' );
				$lst_res= SaleBiz::querySalePreAndSublevelRelationship($sale_id);
				$this->responseSuccess ( $lst_res );
				break;
			case 'delsalerelationship':
				
				$sale_id = I ( 'sale_id' );
				$lst_res= SaleBiz::delSaleRelationship($sale_id);
				$this->responseSuccess ( $lst_res );
				break;
			case 'addpresalelevel':
				$sale_id= I('sale_id');
				$parent_sale_id=I('parent_sale_id');
				
				$lst_res= SaleBiz::addPreSalelevel($sale_id, $parent_sale_id);
			   break;
			case 'addbatchsubsalelevel':
				$sale_id_list=I('sale_id_list');
				$parent_sale_id=I('parent_sale_id');
				$lst_res= SaleBiz::addBatchSubSalelevel($sale_id_list, $parent_sale_id);
				break;
			default :
				$this->responseFail ( 5, '无法找到服务方法' );
				break;
		}
	}
	
	/**
	 * 客户处理
	 *
	 * @param
	 *        	$util
	 */
	public function userService($util) {
		switch (strtolower ( $util )) {
			case 'saveorupdate' :
				$userId = I ( 'user_id' );
				$user = array (
						'user_name' => I ( 'user_name' ),
						'real_name' => I ( 'real_name' ),
						'email' => I ( 'email' ),
						'cellphone' => I ( 'cellphone' ),
						'sex' => I ( 'sex' ),
						'birthday' => I ( 'birthday' ),
						'phone' => I ( 'phone' ),
						'share_code' => I ( 'share_code' ),
						'account_type' => I ( 'account_type' ),
						'account_source' => I ( 'account_source' ),
						'account_name' => I ( 'account_name' ),
						'account_name' => I ( 'account_name' ),
						'province_id' => I ( 'province_id' ),
						'province_name' => I ( 'province_name' ),
						'city_id' => I ( 'city_id' ),
						'city_name' => I ( 'city_name' ),
						'district_id' => I ( 'district_id' ),
						'district_name' => I ( 'district_name' ),
						'address' => I ( 'address' ),
						'amount' => I ( 'amount' ),
						'points' => I ( 'points' ),
						'status' => I ( 'status' ) 
				);
				
				if (empty ( $userId )) {
					$user ['user_id'] = UserBiz::generateId ();
					$user ['register_date'] = date ( "y-m-d H:i:s", time () );
					$user ['register_source'] = 3;
					$user ['register_ip'] = get_client_ip ();
					$user ['create_user'] = "whaleyinfo.info UserBiz.adduser";
					$user ['create_date'] = date ( "y-m-d H:i:s", time () );
					$user ['password'] = md5 ( UserBiz::randStr () );
					$msg = UserBiz::addUser ( $user );
					
					if (! empty ( $msg )) {
						$this->responseFail ( 500, $msg );
					} else {
						$this->responseSuccess ();
					}
					
					return;
				} else {
					$user ['user_id'] = $userId;
					$user ['update_user'] = "whaleyinfo.info UserBiz.updateuser";
					$user ['update_date'] = date ( "y-m-d H:i:s", time () );
					
					$msg = UserBiz::updateUser ( $user );
					if (! empty ( $msg )) {
						$this->responseFail ( 500, $msg );
					} else {
						$this->responseSuccess ();
					}
					return;
				}
			case 'queryuser' :
				$result = UserBiz::queryUser ( I ( 'user_name' ), I ( 'real_name' ), I ( 'email' ), I ( 'cellphone' ), I ( 'pageSize' ), I ( 'index' ) );
				$this->responseSuccess ( $result );
				return;
		}
	}
	public function commonService($util) {
		switch ($util) {
			case 'getAllProvince' :
				$lst_en = CommonBiz::getAllProvince ();
				$this->responseSuccess ( $lst_en );
				break;
			case 'getCityListByProvinceId' :
				$province_id = I ( 'province_id' );
				$lst_en = CommonBiz::getCityListByProvinceId ( $province_id );
				$this->responseSuccess ( $lst_en );
				break;
			case 'getDistrictListByCityId' :
				$city_id = I ( 'city_id' );
				$lst_en = CommonBiz::getDistrictByCityId ( $city_id );
				$this->responseSuccess ( $lst_en );
				break;
			default :
				$this->responseFail ( 5, '无法找到服务方法' );
				break;
		}
	}
	
	/**
	 * admin 模块
	 *
	 * @param string $util
	 *        	方法名
	 */
	public function adminService($util) {
		switch (strtolower ( $util )) {
			case 'login' :
				// 用户登陆
				$user_id = I ( 'param.user_id' );
				$password = I ( 'param.password' );
				
				$error_msg = AdminBiz::login ( $user_id, $password );
				
				if (empty ( $error_msg )) {
					$this->responseSuccess ();
				} else {
					$this->responseFail ( 5, $error_msg );
				}
				return;
			case 'logout' :
				// 用户登陆
				$user_id = I ( 'param.user_id' );
				$error_msg = AdminBiz::logout ( $user_id );
				if (empty ( $error_msg )) {
					$this->responseSuccess ();
				} else {
					$this->responseFail ( 5, $error_msg );
				}
				return;
			default :
				$this->responseFail ( 5, '无法找到服务方法' );
		}
	}
	public function orderService($util) {
		switch (strtolower ( $util )) {
			case 'orderquery' :
				$thirdOrderId = I ( 'third_order_id' );
				$receiverMobile = I ( 'receiver_mobile' );
				$orderId = I ( 'order_id' );
				$reveiverAdd = I ( 'consignee_address' );
				$orderStartDate = I ( 'order_date' );
				$orderEndDate = I ( 'order_end_time' );
				$index = I ( 'index' );
				$pageSize = I ( 'pageSize' );
				$orderStatus = I ( 'taobao_order_status' );
				$cashBackStatus = I ( 'cash_back_status' );
				$invoiceKind = I ( 'invoice_kind' );
				$invoiceStatus = I ( 'invoice_status' );
				$message = I ( 'message' );
				$orderType = I ( 'orderType' );
				$invoiceDate = I ( 'invoiceDate' );
				$orderEndTime = I ( 'orderEndTime' );
				$orderEndTimeEnd = I ( 'orderEndTimeEnd' );
				$consigneeName = I ( 'consignee_name' );
				
				$reultList = OrderBiz::queryOrderByPara ( $thirdOrderId, $receiverMobile, $orderId, $reveiverAdd, $orderStartDate, $orderEndDate, $orderStatus, $cashBackStatus, $invoiceKind, $invoiceStatus, $consigneeName, $message, $orderType, $invoiceDate, $orderEndTime, $orderEndTimeEnd, $index );
				
				$this->responseSuccess ( $reultList );
				return;
			case 'invoicequery' :
				$thirdOrderIds = I ( 'third_order_ids' );
				$orderStartDate = I ( 'order_date' );
				$orderEndDate = I ( 'order_end_time' );
				
				$cashBackStatus = I ( 'cash_back_status' );
				$message = I ( 'message' );
				$orderType = I ( 'order_type' );
				$index = I ( 'index' );
				$pageSize = I ( 'pageSize' );
				$reultList = OrderBiz::queryInvoiceByPara ( $thirdOrderIds, $orderStartDate, $orderEndDate, $cashBackStatus, $message, $orderType, $index );
				
				$this->responseSuccess ( $reultList );
				return;
			case 'updateinvoicename' :
				$thirdOrderIds = I ( 'third_order_ids' );
				$reultList = OrderBiz::queryUpdateInvoiceNameByPara ( $thirdOrderIds );
				$this->responseSuccess ( $reultList );
				return;
			case 'openinvoice' :
				$orderIds = I ( 'order_ids' );
				$invoiceType = I ( 'invoice_type' );
				//OrderBiz::UpdateOrderInfoInvoiceStatus ( $orderIds, $invoiceType );
				
				$msg = OrderBiz::AddOrderInvoice($orderIds, $invoiceType, 'whaleyinfo.order.AjaxService.order openinvoice' );
				$this->responseSuccess ($msg);
				return;
			case 'redinvoice' :
				$orderId = I ( 'order_id' );
				$redReason = I ( 'red_reason' );
				OrderBiz::redInvoiceBiz ( $orderId, $redReason );
				return;
			case 'updateinvoicetitle' :
				$thirdOrderId = I ( 'third_order_id' );
				$invoice_title = I ( 'invoice_title' );
				OrderBiz::UpdateOrderInfoInvoiceTitle ( $thirdOrderId, $invoice_title );
				
				$this->responseSuccess ( null );
				return;
			case 'updateinvoiceaddress' :
				$thirdOrderId = I ( 'third_order_id' );
				$invoice_address = I ( 'invoice_address' );
				OrderBiz::UpdateOrderInfoInvoiceAddress ( $thirdOrderId, $invoice_address );
				$this->responseSuccess ( null );
				return;
			case 'updateorderstatus' :
				$order_id = I ( 'order_id' );
				$return_en = OrderBiz::UpdateOrderStatus ( $order_id, 31, 'whaleyinfo.order.Ajax order.updateorderstatus' );
				$this->responseSuccess ( $return_en );
				return;
			case 'updateinvoicekind' :
				$thirdOrderId = I ( 'third_order_id' );
				$invoiceKind = I ( 'invoice_Kind' );
				OrderBiz::changeInvoiceKind ( $thirdOrderId, $invoiceKind );
				$this->responseSuccess ( null );
				return;
			case 'searchorderinfolist' :
				$order_info_en = array (
						'order_id' => I ( 'order_id' ),
						'dealer_id' => I ( 'dealer_id' ),
						'dealer_name' => I ( 'dealer_name' ),
						'order_status' => I ( 'order_status' ),
						'payment_status' => I ( 'payment_status' ),
						'dealer_type' => I ( 'dealer_type' ),
						'start_date' => I ( 'start_date' ),
						'end_date' => I ( 'end_date' ),
						'dealer_channel' => I ( 'dealer_channel' ),
						'page_index' => I ( 'page_index' ),
						'page_size' => I ( 'page_size' ) 
				);
				$return_en = OrderInfoBiz::searchorderinfolist ( $order_info_en );
				
				$this->responseSuccess ( $return_en );
				return;
			case 'searchpaperinvlist' :
				$order_info_en = array (
						'order_id' => I ( 'order_id' ),
						'dealer_id' => I ( 'dealer_id' ),
						'dealer_name' => I ( 'dealer_name' ),
						'order_status' => I ( 'order_status' ),
						'payment_status' => I ( 'payment_status' ),
						'dealer_type' => I ( 'dealer_type' ),
						'start_date' => I ( 'start_date' ),
						'end_date' => I ( 'end_date' ),
						'start_o_date' => I ( 'start_o_date' ),
						'end_o_date' => I ( 'end_o_date' ),
						'index' => I ( 'index' ),
						'pageSize' => I ( 'pageSize' ) 
				);
				$return_en = OrderInfoBiz::searchPaperInvlist ( $order_info_en );
				$this->responseSuccess ( $return_en );
				return;
			case 'paperinvsave' :   //经销商纸质发票保存
				$lst_invoice = I('lst_invoice');
				$oids = I('oids');
				$msg = OrderInfoBiz::paperInvSave($lst_invoice, $oids);
				if (!empty($msg)) {
					$this->responseFail(500, $msg);
				} else {
					$this->responseSuccess();
				}
				return;
			default :
				$this->responseFail ( 5, '无法找到服务方法' );
		}
	}
	public function dealerService($util) {
		switch ($util) {
			
			case 'validateDealer' :
				$dealer_name = I ( 'dealer_name' );
				$dealer_type = I ( 'dealer_type' );
				$discount_rate = I ( 'discount_rate' );
				$business_leader = I ( 'business_leader' );
				$business_leader_cellphone = I ( 'business_leader_cellphone' );
				$area_name = I ( 'area_name' );
				$province_id = I ( 'province_id' );
				$province_name = I ( 'province_name' );
				$city_id = I ( 'city_id' );
				$city_name = I ( 'city_name' );
				$operation_pattern = I ( 'operation_pattern' );
				$registered_capital = I ( 'registered_capital' );
				$leal_person = I ( 'leal_person' );
				$bank_name = I ( 'bank_name' );
				$bank_no = I ( 'bank_no' );
				$tax_no = I ( 'tax_no' );
				$dealer_id_card_no = I ( 'dealer_id_card_no' );
				$dealer_id_card_image_list1 = I ( 'dealer_id_card_image_list1' );
				$dealer_id_card_image_list2 = I ( 'dealer_id_card_image_list2' );
				$business_license_no = I ( 'business_license_no' );
				$business_license_image1 = I ( 'business_license_image1' );
				$finance_leader = I ( 'finance_leader' );
				$finance_leader_cellphone = I ( 'finance_leader_cellphone' );
				$invoice_address = I ( 'invoice_address' );
				$remark = I ( 'remark' );
				$sign_status = I ( 'sign_status' );
				$sign_date = I ( 'sign_date' );
				$contract_start_date = I ( 'contract_start_date' );
				$contract_end_date = I ( 'contract_end_date' );
				$status = I ( 'status' );
				$add_dealer_en = array (
						'dealer_name' => $dealer_name,
						'dealer_type' => $dealer_type,
						'discount_rate' => $discount_rate,
						'cash_back_rate' => I ( 'cash_back_rate' ),
						'business_leader' => $business_leader,
						'business_leader_cellphone' => $business_leader_cellphone,
						'area_name' => $area_name,
						'province_id' => $province_id,
						'province_name' => $province_name,
						'city_id' => $city_id,
						'city_name' => $city_name,
						'operation_pattern' => $operation_pattern,
						'registered_capital' => $registered_capital,
						'leal_person' => $leal_person,
						'bank_name' => $bank_name,
						'bank_no' => $bank_no,
						'tax_no' => $tax_no,
						'dealer_id_card_no' => $dealer_id_card_no,
						'dealer_id_card_image_list1' => $dealer_id_card_image_list1,
						'dealer_id_card_image_list2' => $dealer_id_card_image_list2,
						'business_license_no' => $business_license_no,
						'business_license_image1' => $business_license_image1,
						'finance_leader' => $finance_leader,
						'finance_leader_cellphone' => $finance_leader_cellphone,
						'invoice_address' => $invoice_address,
						'registered_address' =>I('registered_address'),
						'registered_tel' =>I('registered_tel'),
						'remark' => $remark,
						'amount' => $amount,
						'points' => $points,
						'sign_status' => $sign_status,
						'sign_date' => $sign_date,
						'contract_start_date' => $contract_start_date,
						'contract_end_date' => $contract_end_date,
						'status' => $status,
						'create_user' => "whaleyinfo.order DealerBiz.addDealer",
						'create_date' => date ( "y-m-d H:i:s", time () ) 
				);
				
				$error_msg = DealerBiz::validateDealer ( $add_dealer_en );
				if (empty ( $error_msg )) {
					$this->responseSuccess ();
				} else {
					$this->responseFail ( 5, $error_msg );
				}
				break;
			case 'validateDealerAmountApply' :
				$amount = I ( 'amount' );
				$error_msg = "";
				if (! is_numeric ( $amount )) {
					$error_msg = "请输入正确的金额！";
				}
				
				if ($amount < 0) {
					
					$error_msg = "请输入大于0 的金额！";
				}
				if (empty ( $error_msg )) {
					$this->responseSuccess ();
				} else {
					$this->responseFail ( 5, $error_msg );
				}
				
				break;
			case 'queryDealerByPara' :
				$dealer_name = I ( 'dealer_name' );
				$dealer_type = I ( 'dealer_type' );
				$business_leader = I ( 'business_leader' );
				$k3_code = I ( 'k3_code' );
				$area_name = I ( 'area_name' );
				$sign_status = I ( 'sign_status' );
				$status = I ( 'status' );
				$dealer_channel = I ( 'dealer_channel' );
				$pageSize = I ( 'pageSize' );
				$index = I ( 'index' );
				
				$lst_res = DealerBiz::queryDealerByPara ( $dealer_name, $dealer_type, $business_leader, $area_name, $sign_status, $status, $k3_code, $dealer_channel, $pageSize, $index );
				
				$this->responseSuccess ( $lst_res );
				
				break;
			case 'dealerAmountUpdate' :
				$dealer_id = I ( 'dealer_id' );
				$amount_type = I ( 'amount_type' );
				$dealer_channel = I ( 'dealer_channel' );
				$amount = I ( 'amount' );
				$remark = I ( 'remark' );
				
				$error_msg = DealerBiz::validateDealerAmount ( $dealer_id, $dealer_channel, $amount_type, $amount );
				if (empty ( $error_msg )) {
					// 更新金额
					DealerBiz::updateDealerAmount ( $dealer_id, $amount_type, $amount, $remark );
					$this->responseSuccess ();
				} else {
					$this->responseFail ( 5, $error_msg );
				}
				
				break;
			case 'dealerCashBackAmountUpdate' :
				$dealer_id = I ( 'dealer_id' );
				$amount_type = I ( 'amount_type' );
				$dealer_channel = I ( 'dealer_channel' );
				$amount = I ( 'amount' );
				$remark = I ( 'remark' );
			
				$error_msg = DealerBiz::validateDealerCashBackAmount ( $dealer_id, $dealer_channel, $amount_type, $amount );
				if (empty ( $error_msg )) {
					// 更新金额
					DealerBiz::updateDealerCashBackAmount ( $dealer_id, $amount_type, $amount, $remark );
					$this->responseSuccess ();
				} else {
					$this->responseFail ( 5, $error_msg );
				}
			
				break;
			case 'calcDealerCashBackAmount' :
				$dealer_id = I ( 'dealer_id' );
				$dealer_name = I ( 'dealer_name' );
				$start_date = I ( 'start_date' );
				$end_date = I ( 'end_date' );
				
				$lst_res = DealerBiz::calcDealerCashBackAmountByPara ( $dealer_id, $dealer_name, $start_date, $end_date );
				
				if (! empty ( $lst_res )) {
					$this->responseSuccess ( $lst_res );
				} else {
					$this->responseFail ( 5, "没有查询到相关数据！" );
				}
				
				break;
			case 'queryDealerAmountByPara' :
				$dealer_id = I ( 'dealer_id' );
				
				$amount_type = I ( 'amount_type' );
				$dealer_channel = I ( 'dealer_channel' );
				$start_date =I('start_date');
				$end_date =I('end_date');
				
				$pageSize = I ( 'pageSize' );
				$index = I ( 'index' );
				
				$lst_res = DealerBiz::queryDealerAmountByPara ( $dealer_id, $amount_type, $dealer_channel,$start_date,$end_date, $pageSize, $index );
				
				$this->responseSuccess ( $lst_res );
				
				break;
			case 'queryDealerCashBackAmountByPara' :
				$dealer_id = I ( 'dealer_id' );
			
				$amount_type = I ( 'amount_type' );
				$dealer_channel = I ( 'dealer_channel' );
				$start_date=I('start_date');
				$end_date =I('end_date');
				$pageSize = I ( 'pageSize' );
				$index = I ( 'index' );
			
				$lst_res = DealerBiz::queryDealerCashBackAmountByPara ( $dealer_id, $amount_type, $dealer_channel,$start_date,$end_date, $pageSize, $index );
			
				$this->responseSuccess ( $lst_res );
			
				break;
			case 'queryDealerChargeAmountByPara' :
				$dealer_id = I ( 'dealer_id' );
				$dealer_name = I ( 'dealer_name' );
				$recharge_status=I('recharge_status');
				$pageSize = I ( 'pageSize' );
				$index = I ( 'index' );
				$dealer_channel = I ( 'dealer_channel' );
				$user_id = cookie ( 'login_user_id' );
				$sale_en = M ( 'sale_user' )->where ( "sale_name='%s'", $user_id )->find ();
				if (empty ( $sale_en )) {
					$lst_res = DealerBiz::queryDealerChargeAmountByPara ( $dealer_id, $dealer_name, $dealer_channel, $recharge_status,$pageSize, $index );
				} else {
					
					$lst_res = DealerBiz::queryDealerChargeAmountBySale ( $dealer_id, $dealer_name, $sale_en ['sale_id'], $recharge_status,$pageSize, $index );
				}
				$this->responseSuccess ( $lst_res );
				
				break;
			case 'getUserID' :
				$return_en = DealerBiz::generateUserId ();
				$this->responseSuccess ( $return_en );
				break;
			case 'addDealerOrder' :
				$dealer_id = I ( 'dealer_id' );
				$return_en = DealerBiz::queryDealerByIdAndName ( $dealer_id );
				$this->responseSuccess ( $return_en );
				break;
			case 'submitDealerOrder' :
				$dealer_id          = I ( 'dealer_id' );
				$select_address_id  = I ( 'select_address_id' );
				$sku_list_str       = I ( 'sku_list_str' );
				$remark             = I ( 'remark' );
				
				$payment_type       = I ( 'payment_type' );
				$addDiscountAmount  = I ( 'addDiscountAmount' );
				$subDiscountAmount  = I ( 'subDiscountAmount' );
				$dealer_channel     = I('dealer_channel');
                $dealer_cashback_amount = I ( 'dealer_cashback_amount' );


                //东方有线经销商，订单编号以DF开头
                $order_id	= '';
                if($dealer_id == 'DL1739763'){
                	$order_id	= CommonBiz::getDFYXOrderId('DF');	
                }
                else{
                	$order_id	= CommonBiz::getDKHOrderId('DKH');
                }
                

				$error_msg = DealerBiz::submitDealerOrder ( $dealer_id, $select_address_id,
                    $sku_list_str, $remark, $order_id, $payment_type,
                    $addDiscountAmount,$subDiscountAmount,
                    $dealer_cashback_amount
                );

				if (empty ( $error_msg )) {
					
					if ($dealer_channel == 1) {
						
						$url = C ( 'OrderConfig.dkh_success_page' ) . '?order_id=' . $order_id;
						$this->responseSuccess ( $url );
					} else if ($dealer_channel == 2) {
						
						$url = C ( 'OrderConfig.vrdkh_success_page' ) . '?order_id=' . $order_id;
						$this->responseSuccess ( $url );
					} else if ($dealer_channel == 3) {
						
						$url = C ( 'OrderConfig.stdkh_success_page' ) . '?order_id=' . $order_id;
						$this->responseSuccess ( $url );
					} 

					else {
						
						$this->responseFail ( 5, "非法的渠道" );
					}
				} else {
					$this->responseFail ( 5, $error_msg );
				}
				
				break;
			case 'CheckDealerMinSalePrice' :
				$dealer_id = I ( 'dealer_id' );
				$sku_list_str = I ( 'sku_list_str' );
				$error_msg = DealerBiz::checkDealerMinSalePrice ( $dealer_id, $sku_list_str );
				if (empty ( $error_msg )) {
					$this->responseSuccess ();
				} else {
					$this->responseFail ( 5, $error_msg );
				}
				break;
			case 'SearchDearlerForOrder' :
				$dealer_id = I ( 'dealer_id' );
				$dealer_name = I ( 'dealer_name' );
				$dealer_channel = I ( 'dealer_channel' );
				
				$result = DealerBiz::searchDearlerForOrder ( $dealer_id, $dealer_name, $dealer_channel );
				
				$this->responseSuccess ( $result );
				
				break;
				
			case 'wharehouse' :
				$wharehouse_id = I ( 'wharehouse_id' );
				
				$post_data = array(
						"wareHouseId"=> $wharehouse_id
				);
				$result=CommonBiz::httpPostJson("http://123.59.131.142:8081/whaley-job/wms/stockQueryCheck", $post_data);
				$response = json_decode($result['response']);
				$list_inv_infos = $response->data;
 				$lst_product_info=json_decode(json_encode($list_inv_infos),true);
				$this->responseSuccess ( $lst_product_info );
				break;
				
			case 'partofexpress' :
				$msg = DealerBiz::partofexpress();
				if (!empty($msg)) {
					$this->responseFail(500, $msg);
				} else {
					$this->responseSuccess();
				}
				return;
			default :
				$this->responseFail ( 5, '无法找到服务方法' );
				break;
		}
	}
	public function responseSuccess($result) {
		// 0，正确；1，参数错误；2,安全码校验失败;3，无法反序列化；4,服务器错误;5，业务逻辑错误
		$return_json = array (
				'IsSuccess' => 1,
				'ErrorMsg' => '',
				'ErrorCode' => 0,
				'Result' => $result 
		);
		$this->ajaxReturn ( $return_json );
	}
	public function responseFail($error_code, $error_msg) {
		// 0，正确；1，参数错误；2,安全码校验失败;3，无法反序列化；4,服务器错误;5，业务逻辑错误
		$return_json = array (
				'IsSuccess' => 0,
				'ErrorMsg' => $error_msg,
				'ErrorCode' => $error_code,
				'Result' => null 
		);
		$this->ajaxReturn ( $return_json );
	}
}